/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dilean.bcryptpasswordencoder;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 *
 * @author Дмитрий
 */
public class BCryptEncoder {

    public BCryptEncoder() {
    }

    public static String encode(String pass) {

        String password = pass;
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        String hashedPassword = passwordEncoder.encode(password);

        System.out.println(passwordEncoder.matches(password, hashedPassword));
        return hashedPassword;
    }

    public static String matche(String pass, String hashedPassword) {
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        if(passwordEncoder.matches(pass, hashedPassword)){
            return "Password and hash match";
        }
        else{
            return "Password and hash do NOT match";
        }
    }
}
